package com.ktgj.flight.service.impl;

import java.util.Date;
import java.util.List;

import com.ktgj.common.core.domain.R;
import com.ktgj.common.core.utils.DateUtils;
import com.ktgj.customer.api.domain.Employee;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ktgj.flight.mapper.FlightSalespolicyMapper;
import com.ktgj.flight.domain.FlightSalespolicy;
import com.ktgj.flight.service.IFlightSalespolicyService;

import javax.servlet.http.HttpServletResponse;

/**
 * 机票销售政策维护Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-06-06
 */
@Service
public class FlightSalespolicyServiceImpl implements IFlightSalespolicyService
{
    @Autowired
    private FlightSalespolicyMapper flightSalespolicyMapper;

    /**
     * 查询机票销售政策维护
     * 
     * @param policyId 机票销售政策维护ID
     * @return 机票销售政策维护
     */
    @Override
    public FlightSalespolicy selectFlightSalespolicyById(Long policyId)
    {
        return flightSalespolicyMapper.selectFlightSalespolicyById(policyId);
    }

    /**
     * 查询机票销售政策维护列表
     * 
     * @param flightSalespolicy 机票销售政策维护
     * @return 机票销售政策维护
     */
    @Override
    public List<FlightSalespolicy> selectFlightSalespolicyList(FlightSalespolicy flightSalespolicy)
    {
        if (flightSalespolicy.getIsUse().longValue() == 1l)
            flightSalespolicy.setIsUse(0l);
        if (flightSalespolicy.getIsUse().longValue() == 2l)
            flightSalespolicy.setIsUse(1l);

        List<FlightSalespolicy> flightSalespolicies = flightSalespolicyMapper.selectFlightSalespolicyList(flightSalespolicy);
        return flightSalespolicies;
    }

    /**
     * 新增机票销售政策维护
     * 
     * @param flightSalespolicy 机票销售政策维护
     * @return 结果
     */
    @Override
    public int insertFlightSalespolicy(Employee employee, FlightSalespolicy flightSalespolicy) throws Exception {
        Date nowDate = DateUtils.getNowDate();
        flightSalespolicy.setCreateTime(nowDate);
        flightSalespolicy.setOperationTime(nowDate);
        flightSalespolicy.setIsDelete(0l);
        if (employee != null){
            flightSalespolicy.setEmployeeId(employee.getEmployeeId());
        }
        else {
            throw new Exception("登录已过期");
        }
        return flightSalespolicyMapper.insertFlightSalespolicy(flightSalespolicy);
    }

    /**
     * 修改机票销售政策维护
     * 
     * @param flightSalespolicy 机票销售政策维护
     * @return 结果
     */
    @Override
    public int updateFlightSalespolicy(Employee employee, FlightSalespolicy flightSalespolicy) {
        Date nowDate = DateUtils.getNowDate();
        flightSalespolicy.setOperationTime(nowDate);
        if (employee != null){
            flightSalespolicy.setEmployeeId(employee.getEmployeeId());
        }
        return flightSalespolicyMapper.updateFlightSalespolicy(flightSalespolicy);
    }

    /**
     * 批量删除机票销售政策维护
     * 
     * @param policyIds 需要删除的机票销售政策维护ID
     * @return 结果
     */
    @Override
    public int deleteFlightSalespolicyByIds(Long[] policyIds)
    {
        return flightSalespolicyMapper.deleteFlightSalespolicyByIds(policyIds);
    }

    /**
     * 删除机票销售政策维护信息
     * 
     * @param policyId 机票销售政策维护ID
     * @return 结果
     */
    @Override
    public int deleteFlightSalespolicyById(Long policyId)
    {
        return flightSalespolicyMapper.deleteFlightSalespolicyById(policyId);
    }

    @Override
    public int delete(Long policyId) {
        FlightSalespolicy flightSalespolicy = new FlightSalespolicy();
        flightSalespolicy.setPolicyId(policyId);
        flightSalespolicy.setIsDelete(1L);
        return flightSalespolicyMapper.updateFlightSalespolicy(flightSalespolicy);
    }
}
